import java.util.Vector;

import processing.core.PApplet;
import processing.core.PVector;

@SuppressWarnings("serial")
public class FechandoUmaForma extends PApplet{
	
	Vector<PVector> points;
	
	@Override
	public void setup() {
		size(800, 600);
		points = new Vector<PVector>();
	}

	@Override
	public void draw() {
		background(255);
		for (PVector point : points) {
			point(point.x, point.y);
		}
	}
	
	public boolean contem(PVector current){
		boolean contem = false;
		for (PVector point : points) {
			float cX = current.x;
			float cY = current.y;
			float pX = point.x;
			float pY = point.y;
			if(cX == pX && cY == pY){
				contem = true;
			}
		}
		return contem;
	}

	@Override
	public void mouseDragged() {
		PVector current = new PVector(mouseX, mouseY);
		if(!contem(current)){
			points.add(current);
		} else {
			System.out.println("Ok");
			// aqui eu pego os pontos
			points.clear();
		}
	}

	public static void main(String[] args) {
		PApplet.main(new String[] { "--bgcolor=#FFFFFF", "FechandoUmaForma" });
	}
	
}
